perm filename REPLCE.TEX[1,RWF] blob
sn#545536 filedate 1980-11-13 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 %Replaces material on pp 11 and 24
C00011 ENDMK
C⊗;
%Replaces material on pp 11 and 24
{\bf Pascal Note: Printing Format}
Pascal distinguishes between two kinds of expressions for numbers:
integer expressions and real expressions. Integer expressions are written
without decimal points, using only integer variables, and using only the
functions and operators {\tt +,\hbox{-},*,DIV,ABS}, and a few others we will meet
later. Real expressions are those which make any use of decimal points, real
variables, or any of the functions {\tt /,SQRT,EXP}, logarithmic, or trigonometric
functions. In programming languages, an \undertext{integer} number is a whole
number, whether positive, negative, or zero. A \undertext {real} number is what
is ordinarily just called a number, as opposed to an imaginary or complex number;
it may or may not be a whole number. Integer and real expressions are printed
differently, when they occur in Pascal {\tt WRITE} commands.
If $\Iscr$ is an integer expression, {\tt WRITE} $\Iscr$ prints the
value of I in a field of twelve characters, beginning with some blank spaces,
then a possible minus sign, then the digits of the number; for example:
\startcode
\sp\sp\sp\sp\sp\sp\sp\sp\sp\sp\sp0
\sp\sp\sp\sp\sp\sp\sp\sp-123
-12345678901
\endcode
If you know that $\Iscr$ will not require more than $\Nscr$ character positions,
you can use the command {\tt WRITE(}$\Iscr${\tt :}$\Nscr${\tt )} to print $\Iscr$ in
an $\Nscr$-character field;
for example, {\tt WRITE(-123:5, 0:3, 123456:6)}
prints
{\tt \sp-123\sp\sp0123456}
If $\Rscr$ is a real expression, {\tt WRITE(}$\Rscr${\tt )} prints the
value of $\Rscr$ in a field of sixteen characters, in a form of scientific
notation, as exemplified below:
\twocolalign{
{\tt Value}⊗{\tt Printed Form}\cr
$1$⊗{\tt\sp1.000000000\sp\sp\sp\sp}\cr
$22/7$⊗{\tt\sp3.142857143\sp\sp\sp\sp}\cr
$-1234.56789 (ie, 1.23456789 \times 10↑3)$⊗{\tt -1.234567890E+03}\cr
$0.00123456789 (ie, 1.23456789 \times 10↑{-3})$⊗{\tt \sp 1.234567890E-03}\cr
}%end of twocolalign
%\twocolalign{
%{\tt Value}⊗{\tt Printed Form}\cr
%$1$⊗{\tt\sp1.000000000\sp\sp\sp\sp}\cr
%22/7⊗{\tt \sp 3.142857143\sp\sp\sp\sp}\cr
%-1234.56789 (ie, 1.23456789 \times 10↑3)⊗{\tt -1.234567890E+03}\cr
%.00123456789 (ie, 1.23456789 \times 10↑{-3})⊗{\tt \sp 1.234567890E-03}\cr
%}%end of twocolalign
The format consists of a blank or minus sign, a ten digit number with decimal
point after the first digit, ``E'', a two-digit power of ten. If the number lies
between 1 and {\tt 9.999999999}, the power of ten is omitted. In all, sixteen
characters are needed for a real value, so up to eight real values can appear across
a printed page, and up to five across the terminal screen.
You can shorten the number by specifying a field length after the expression;
{\tt WRITE(}$\Rscr${\tt :}$\Nscr${\tt )} prints the value of $\Rscr$ in an
$\Nscr$-character field. Since six characters are used for sign, decimal point,
and power of ten, the number is printed with $\Nscr$-6 significant digits. For
example, {\tt WRITE(SQRT(2):10, 1/3:14)} prints
{\tt\sp7.071E-01\sp3.3333333\sp\sp\sp\sp} .
To print a real number in a format without a separate power of ten, and with
the decimal point in a fixed position, use the form
{\tt WRITE(}$\Rscr${\tt :}$\Nscr${\tt :}$\Dscr${\tt )} , where
$\Nscr$ is the total field length and $\Dscr$ is the number of digits to the
right of the decimal point. For example,
{\tt WRITE(22/7:7:4, SQRT(2):\ :6)}
prints
{\tt\sp3.1428\sp0.707}
This form of output is called \undertext{fixed (decimal) point} notation,
\sendindex{fixed(decimal) point notation} because the decimal point is always in the
same position in the field.
Within the computer,the values of real expressions are represented as
binary numbers with the equivalent of eight-digit accuracy. As a result, when
such an expression is printed, only the first eight digits ordinarily are correct.
For example, {\tt WRITE(1/5)} prints \undertext{?????} . It is usually desirable,
then, to shorten the printed value to no more than fourteen characters. When
this is done, however, the current system does not round the number to the desired
number of digits; rather, it simply discards digits on the right.
{\tt WRITE(9.9999999:5:2)}
prints {\tt\sp9.99} , not {\tt 10.00} .
There is no simple way to cure this problem except for positive nummbers printed
in fixed-point format. For such numbers, adding 5 in the most significant
discarded decimal place will correctly round the number. For example, if {\tt R1}
and {\tt R2} have the values 9.9949 and 9.9951 respectively,
{\tt WRITE(R1\ +\ .005:5:2,`\sp',R2\ +\ .005:5:2)}
prints
{\tt\sp9.99\sp10.00}
\allowbreak
\example
\startcode
BEGIN
WRITELN(`\sp{X}\sp\sp\sp\sp\sp{EXP(X)}\sp\sp\sp\sp\sp\sp{Y}\sp\sp{SIN(Y)');}
FOR I:= 0 TO 10 DO
WRITELN(I:3,EXP(I) + .00005:15:4 ,
I/10 + .05:4:1, SIN(I/10) + .0000005:8:6)
END.
\endcode
%\sendindex{fixed(decimal)point notation}